//
//  PresMovieController.m
//  HouseShow
//
//  Created by  on 11-12-29.
//  Copyright (c) 2011年 __MyCompanyName__. All rights reserved.
//

#import "PresMovieController.h"

@implementation PresMovieController
@synthesize m_Tid;
-(void) viewDidLoad{
    [self.view setBackgroundColor:[UIColor blackColor]];
    UIToolbar* tTool = [[UIToolbar alloc] initWithFrame:CGRectMake(0, 0, ScreenWidth, 44)];
    tTool.barStyle = UIBarStyleBlackTranslucent;
    tTool.tag = 0x44;
    UIBarButtonItem *Button1 = [[UIBarButtonItem alloc] initWithTitle:@"返回" style:UIBarButtonItemStylePlain target:self action:@selector(backToMainUI)];
    [tTool setItems:[NSArray arrayWithObjects:Button1, nil]];
    [Button1 release];
    [self.view addSubview:tTool];
    [tTool release];
    
    NSString* tTid =[NSString stringWithFormat:@"http://unitrue.com.cn:8088/ClientWebPage/dzqk.mp4?tid=%@",m_Tid]; 
//    NSURL* tSee = [[NSURL alloc] initFileURLWithPath:[[NSBundle mainBundle] pathForResource:@"123" ofType:@"mp4"]];
    moviePlayer = [[MPMoviePlayerController alloc] initWithContentURL:[NSURL URLWithString:tTid]];
    moviePlayer.controlStyle = MPMovieControlStyleFullscreen;
    [[moviePlayer view] setFrame:CGRectMake(0, 0, ScreenWidth, ScreenHeight)];
    [self.view addSubview:moviePlayer.view];
    
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(movieFinishedCallback:)  name:MPMoviePlayerPlaybackDidFinishNotification object:nil];
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(movieToStart:)  name:MPMovieSourceTypeAvailableNotification object:nil];
    [moviePlayer play];
}

-(void) dealloc{
    [m_Tid release];
    [moviePlayer release];
}

-(void) backToMainUI{
    [UIApplication sharedApplication].statusBarHidden = YES;
    [self dismissModalViewControllerAnimated:YES];
}

-(void) movieFinishedCallback:(MPMoviePlayerController*)tMovie{
    [UIApplication sharedApplication].statusBarHidden = YES;
    [self dismissModalViewControllerAnimated:YES];
}

-(void) movieToStart:(MPMoviePlayerController*)tMovie{
    [[self.view viewWithTag:0x44] removeFromSuperview];
}

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    // Return YES for supported orientations
    return (interfaceOrientation == UIInterfaceOrientationLandscapeRight);
}

@end
